#ifndef UI_MANAGER_H
#define UI_MANAGER_H

#include <QObject>
#include <QMainWindow>
#include <QMenuBar>
#include <QToolBar>
#include <QTableWidget>
#include <QStatusBar>
#include <QVBoxLayout>
#include <QWidget>
#include <QLabel>
#include <QProgressBar>
#include <QPushButton>
#include <QAction>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QLineEdit>
#include <QTreeView>
#include <QTreeWidget>
#include <QSplitter>
#include <QGroupBox>
#include <QTabWidget>
#include <QComboBox>
#include <QCheckBox>
#include <QHeaderView>
#include <QDateTime>
#ifdef HAVE_TEXT_TO_SPEECH
#include <QTextToSpeech>
#endif

class IDMWindow; // 前向声明

class UIManager : public QObject
{
    Q_OBJECT

public:
    explicit UIManager(IDMWindow *parentWindow, QObject *parent = nullptr);
    ~UIManager();

    // 创建UI组件
    void createMenus();
    void createToolBars();
    void createMainWidgets();
    void createStatusBar();
    void createSystemTrayIcon();
    void setupConnections();
    void setupToolBarActions();
    
    // 应用主题
    void applyTheme();
    void applyCategoryAndListStyles();

    // 获取UI组件
    QMenuBar* menuBar() const { return m_menuBar; }
    QToolBar* mainToolBar() const { return m_mainToolBar; }
    QTabWidget* tabWidget() const { return m_tabWidget; }
    QTableWidget* downloadList() const { return m_downloadList; }
    QTreeWidget* categoryTree() const { return m_categoryTree; }
    QFrame* categoryPanel() const { return m_categoryPanel; }
    QStatusBar* mainStatusBar() const { return m_mainStatusBar; }
    QSystemTrayIcon* trayIcon() const { return m_trayIcon; }
    QLineEdit* searchBox() const { return m_searchBox; }
    QComboBox* filterComboBox() const { return m_filterComboBox; }
    QAction* toggleCategoryPanelAction() const { return m_toggleCategoryPanelAction; }

private:
    IDMWindow *m_parentWindow;
    
    // 菜单栏
    QMenuBar *m_menuBar;
    QMenu *m_fileMenu;
    QMenu *m_downloadMenu;
    QMenu *m_toolsMenu;
    QMenu *m_helpMenu;
    QMenu *m_viewMenu;

    // 文件菜单项
    QAction *m_newDownloadAction;
    QAction *m_batchDownloadAction;
    QAction *m_pauseAction;
    QAction *m_resumeAction;
    QAction *m_cancelAction;
    QAction *m_deleteAction;
    QAction *m_propertiesAction;
    QAction *m_exitAction;

    // 下载菜单项
    QAction *m_addUrlAction;
    QAction *m_pauseSelectedAction;
    QAction *m_resumeSelectedAction;
    QAction *m_deleteSelectedAction;
    QAction *m_scheduleDownloadAction;
    QAction *m_organizeDownloadsAction;
    QAction *m_deleteCompletedAction;
    QAction *m_refreshAction;

    // 工具菜单项
    QAction *m_optionsAction;
    QAction *m_connectToProxyAction;
    QAction *m_disconnectFromProxyAction;
    QAction *m_readAloudAction;

    // 视图菜单项
    QAction *m_toggleThemeAction;

    // 帮助菜单项
    QAction *m_helpContentsAction;
    QAction *m_aboutAction;

    // 工具栏
    QToolBar *m_mainToolBar;
    QAction *m_addUrlToolAction;
    QAction *m_pauseToolAction;
    QAction *m_resumeToolAction;
    QAction *m_deleteToolAction;
    QAction *m_scheduleToolAction;
    QAction *m_openFileToolAction;
    QAction *m_openFolderToolAction;
    QAction *m_propertiesToolAction;
    QAction *m_organizeToolAction;
    QAction *m_deleteCompletedToolAction;
    QAction *m_refreshToolAction;
    QAction *m_toggleCategoryPanelAction;
    QAction *m_readAloudToolAction;

    // 主要部件
    QTabWidget *m_tabWidget;
    QWidget *m_downloadsTab;
    QWidget *m_scheduleTab;
    QWidget *m_youTubeTab;
    QWidget *m_grabberTab;
    
    // 下载列表
    QTableWidget *m_downloadList;
    
    // 侧边栏
    QTreeWidget *m_categoryTree;
    QFrame *m_categoryPanel;
    bool m_categoryPanelVisible;
    
    // 状态栏
    QStatusBar *m_mainStatusBar;
    QLabel *m_statusLabel;
    QProgressBar *m_downloadProgressBar;
    QLabel *m_speedLabel;
    QLabel *m_activeDownloadsLabel;

    // 系统托盘图标
    QSystemTrayIcon *m_trayIcon;
    QMenu *m_trayIconMenu;
    
    // 搜索和过滤控件
    QLineEdit *m_searchBox;
    QComboBox *m_filterComboBox;
};

#endif // UI_MANAGER_H